//
//  HPCardsManagerViewController.m
//  HPZZTong
//
//  Created by Handpay on 14-3-28.
//  Copyright (c) 2014年 Handpay. All rights reserved.
//

#import "HPCardsManagerViewController.h"
#import "CallbackData.h"
#import "ZZTongUtility.h"

@interface HPCardsManagerViewController ()

@end

@implementation HPCardsManagerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    self.title = @"收款卡管理";
    
    [super viewDidLoad];
    
    
    [self.modifyButton setBackgroundImage:[[UIImage imageNamed:@"bluebutton.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateNormal];
    
    [self.modifyButton setBackgroundImage:[[UIImage imageNamed:@"bluebuttonhover.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateHighlighted];
    
    [self initData];
}
- (void)doSendGetBanksReq{
#if ZZT_FOR_TEST
    [self responseCallBackSuccess:NET_ACTION_GET_BANK_LIST withData:@{@"items":@(5),
                                                                  @"list":@[
                                                                          @{@"bankId":@"1",@"bankName":@"农业银行"},
                                                                          @{@"bankId":@"2",@"bankName":@"工商银行"},
                                                                          @{@"bankId":@"3",@"bankName":@"交通银行"},
                                                                          @{@"bankId":@"4",@"bankName":@"建设银行"},
                                                                          @{@"bankId":@"5",@"bankName":@"中国银行"}]}];
#else
    ZZTongClientEngine* zzt = ZZT_CLIENG;
    [zzt.netEngine sendRequest:NET_ACTION_GET_BANK_LIST withParams:@{KEY_CHANNEL: [zzt getChannel]} withDelegate:self];
    [zzt.uiEngine showNetWaiting];
#endif
}
- (void)responseCallBackSuccess:(NSString *)action withData:(NSDictionary *)respData{
    if ([action isEqualToString:NET_ACTION_GET_BANK_LIST]) {
        [HPUIENG removeWaiting];
        NSMutableDictionary* params = nil;
        if (respData) {
            params = [NSMutableDictionary dictionaryWithDictionary:respData];

        }else{
            params = [NSMutableDictionary dictionaryWithCapacity:10];
        }
        CallbackData* callback = [[CallbackData alloc] initWithTarget:self callback:@selector(initData)];
        [params setObject:callback forKey:KEY_CALLBACK];
        
        [HPUIENG showScreen:SCR_MODIFY_CARD params:params];
        [callback release];
    }
}
- (void)responseCallBackFailed:(NSString *)action withErrCode:(NSString *)errCode withErrMsg:(NSString *)msg{
    [HPUIENG showAlert:msg];
}
- (void)initData{
    AccountInfoData* info = ZZT_CLIENG.accountInfo;
    self.bankNameLabel.text = info.bankName;
    UIImage* image = [UIImage imageNamed:[[ZZTongUtility getZZTongUtility] getBankLogoWithName:info.bankName]];
    if (image) {
        self.bankLogoImageView.image = image;
    }
    self.nameLabel.text = info.name;
    
    [Utility adjustFontSizeWithLable:self.nameLabel size:16];
    
    self.cardNoLabel.text = [Utility encryptCardID:info.cardNo];
    self.branchBankLabel.text = info.branchBankName;
}

- (void)dealloc {
    [_modifyButton release];
    [_bankLogoImageView release];
    [_bankNameLabel release];
    [_nameLabel release];
    [_cardNoLabel release];
    [_branchBankLabel release];
    [super dealloc];
}

- (void)viewDidUnload {
    [self setModifyButton:nil];
    [self setBankLogoImageView:nil];
    [self setBankNameLabel:nil];
    [self setNameLabel:nil];
    [self setCardNoLabel:nil];
    [self setBranchBankLabel:nil];
    [super viewDidUnload];
}

- (IBAction)modifyButtonClick:(id)sender {
    [self doSendGetBanksReq];
}
@end
